<?php

namespace app\partner\controller;


use think\Db;
use think\Session;


class Task extends Authorized
{

    public function index()
    {
        $projects =Db::table('project')->order('state desc,id desc')->select();
        $this->assign('projects', $projects);
        return $this->fetch();
    }


    public function state()
    {
        return $this->fetch();
    }
    public function showlist()
    {
        $id = input('id');
        $lists =Db::table('task_record a')
            ->field('a.*,b.username as kf_name')
            ->join('admin b','a.kf_id = b.id')
            ->where('a.task_id',$id)
            ->order('a.id desc')
            ->select();
        $this->assign('lists', $lists);
        return $this->fetch();
    }

    public function show_taskinfo()
    {
        $task=Db::table('task t')
            ->field('t.*,admin.username as kf_name,c.name as user,p.title project_name,p.price_base,p.price')
            ->join('project p','t.project_id = p.id','left')
            ->join('company c','t.company_id = c.id','left')
            ->join('admin','c.kf_id = admin.id','left')
            ->where('t.id',input('id'))
            ->find();
        $this->assign('task', $task);

        return $this->fetch();
    }

    public function stop()
    {
        return $this->fetch();
    }


    public function getList()
    {
        $get_data=$this->request->get();

        $page = $get_data['page'];
        $limit = $get_data['limit'];

        $project_id = input('project_id');
//        $keywords = input('keywords');

        $where['c.id']=Session::get('user.id');
        if (isset($project_id)){
            if ($project_id>0){$where['p.id']=$project_id;}
        }
//        if (!empty($keywords)){
//            $where['company.title']=['like','%'.$keywords.'%'];
//        }

        $count=Db::table('task t')->field('t.*,p.title project_name,c.name company_name,c.kf_id kfid,a.username  kfname,a.qq  kfqq')
            ->join('project p','t.project_id = p.id','left')
            ->join('company c','t.company_id = c.id','left')
            ->join('admin a','c.kf_id = a.id','left')
            ->where($where)->count();

        $rows=Db::table('task t')->field('t.*,p.title project_name,c.name company_name,c.kf_id kfid,a.username  kfname,a.qq  kfqq')
            ->join('project p','t.project_id = p.id','left')
            ->join('company c','t.company_id = c.id','left')
            ->join('admin a','c.kf_id = a.id','left')
            ->where($where)
            ->order('t.id desc')
            ->page($page, $limit)
            ->select();
        return json(['code' =>0,'count' =>$count,'msg'=>'','data'=>$rows]);
    }


}